package com.chengwei.ch.busdemo.activity;


import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.blankj.utilcode.util.ToastUtils;
import com.chengwei.ch.busdemo.R;
import com.chengwei.ch.busdemo.adapter.BuyTicketScanInfAdapter;
import com.chengwei.ch.busdemo.base.BaseActivity;
import com.chengwei.ch.busdemo.view.TitleView;
import com.timmy.tdialog.TDialog;

import java.util.ArrayList;
import java.util.List;


@SuppressLint("Registered")
public class BuyTicketScanInfActivity extends BaseActivity implements BuyTicketScanInfAdapter.SaveEditListener {

    private LinearLayoutManager mLinearLayoutManager = new LinearLayoutManager(this, RecyclerView.VERTICAL, false);
    private BuyTicketScanInfAdapter mBuyTicketScanInfAdapter = new BuyTicketScanInfAdapter(R.layout.item_ticket_buy_inf, new ArrayList<String>());

    private RecyclerView rvListIdCard;

    private TitleView titleBack;
    private Button btnConfirm;
    private List<String> listSite;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ticket_buy_scan_inf);
        initView();
        initClickListener();
    }

    private void initView() {
        rvListIdCard = findViewById(R.id.rvListIdCardBuyTicketScanInf);
        titleBack = findViewById(R.id.titleBackPosition);
        btnConfirm = findViewById(R.id.btnConfirmTicketScanInf);
        initRecycler();
    }

    private void initClickListener() {
        titleBack.addTitleLeftOnClickListener(this);
        btnConfirm.setOnClickListener(this);
    }

    @SuppressLint("SetTextI18n")
    private void initRecycler() {
        listSite = new ArrayList<>();
        listSite.add("");
        listSite.add("");
        listSite.add("");
        rvListIdCard.setLayoutManager(mLinearLayoutManager);
        rvListIdCard.setAdapter(mBuyTicketScanInfAdapter);
        mBuyTicketScanInfAdapter.setNewData(listSite);
        mBuyTicketScanInfAdapter.setOnItemClickListener((adapter, view, position) -> {

        });
    }

    @Override
    public void onClick(View v) {
        Intent intent = new Intent();
        switch (v.getId()) {
            case R.id.IBtnTitleViewLeftBack:
                finish();
                break;
            case R.id.btnConfirmTicketScanInf:
                listSite.set(0, "1111111111111111111111");
                mBuyTicketScanInfAdapter.notifyItemChanged(0);
                // showDialog();
                break;
            default:
                break;
        }
    }

    private void showDialog() {
        new TDialog.Builder(getSupportFragmentManager())
                .setLayoutRes(R.layout.dialog_ticket_buy_confirm)    //设置弹窗展示的xml布局
                .setDimAmount(0.6f)
                .setScreenWidthAspect(BuyTicketScanInfActivity.this, 0.95f)   //设置弹窗宽度(参数aspect为屏幕宽度比例 0 - 1f)
                .setScreenHeightAspect(BuyTicketScanInfActivity.this, 0f)  //设置弹窗高度(参数aspect为屏幕宽度比例 0 - 1f)
                .addOnClickListener(R.id.btnPayTicketDialog, R.id.tvCancelTicketDialog)
                .setOnViewClickListener((viewHolder, view, tDialog) -> {
                    switch (view.getId()) {
                        case R.id.btnPayTicketDialog:
                            ToastUtils.showShort("支付");
                            showPayDialog();
                            break;
                        case R.id.tvCancelTicketDialog:
                            ToastUtils.showShort("取消");
                            tDialog.dismiss();
                            break;
                    }
                })
                .setCancelableOutside(false)
                .create()   //创建TDialog
                .show();    //展示
    }

    private void showPayDialog() {
        new TDialog.Builder(getSupportFragmentManager())
                .setLayoutRes(R.layout.dialog_check_ticket_pay)    //设置弹窗展示的xml布局
                .setDimAmount(0.6f)
                .setScreenWidthAspect(BuyTicketScanInfActivity.this, 0.8f)   //设置弹窗宽度(参数aspect为屏幕宽度比例 0 - 1f)
                .setScreenHeightAspect(BuyTicketScanInfActivity.this, 0f)  //设置弹窗高度(参数aspect为屏幕宽度比例 0 - 1f)
                .setCancelableOutside(true)
                .create()   //创建TDialog
                .show();    //展示
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    /**
     * adtpter 监听edittext
     *
     * @param name
     * @param position
     */
    @Override
    public void saveEdit(String name, Integer position) {
        Log.d("BaseActivity", "name:" + name + ";position:" + position);
    }
}
